<template>
  <div>
    <van-picker
      title="更新性别"
      show-toolbar
      :columns="columnssex"
      @confirm="getuploadProfile"
      @cancel="$parent.$parent.show2 = false"
      :default-index="defaultSex"
    />
  </div>
</template>

<script>
import { getuploadProfile } from '@/api'
export default {
  data() {
    return {
      columnssex: ['女', '男'],
      defaultSex: this.$parent.$parent.UserInfo.gender === '男' ? 0 : 1
    }
  },
  mounted() {
    this.getuploadProfile()
  },
  methods: {
    async getuploadProfile(value, index) {
      try {
        const data = { gender: index }
        await getuploadProfile(data)
        this.$parent.$parent.getUserInfo()
        this.$parent.$parent.show2 = false
        this.$toast.success('性别修改成功!')
      } catch (error) {
        this.$toast.fail('性别修改失败!')
      }
    },

    onCancel() {
      console.log(2)
    }
  }
}
</script>

<style scoped lang="less"></style>
